home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 129_01.zip / 210CONFG.C next >
Text File  |  1993-06-01  |  12KB  |  340 lines

  1. /************************************************************************/
  2. /*                confg.c                 */
  3. /*    configuration program for Citadel bulletin board system.    */
  4. /************************************************************************/
  5. #include <210ctdl.h>
  6. /************************************************************************/
  7. /*                History                 */
  8. /*                                    */
  9. /* 84Dec28 HAW    Now Configure identifies itself.            */
  10. /* 84Apr08 HAW    Update to BDS C 1.50a begun.                */
  11. /* 82Nov20 CrT    Created.                        */
  12. /************************************************************************/
  13.  
  14. /************************************************************************/
  15. /*                Contents                */
  16. /*                                    */
  17. /*    init()            system startup initialization        */
  18. /*    main()                                */
  19. /*    wrapup()        finishes and writes ctdlTabl.sys    */
  20. /************************************************************************/
  21.  
  22. /************************************************************************/
  23. /*    init() -- master system initialization                */
  24. /************************************************************************/
  25. init()
  26. {
  27.     char     getCh(), toUpper();
  28.     unsigned codend(), endExt(), externs(), topOfMem();
  29.     char     c, *msgFile;
  30.  
  31.     usingWCprotocol    = FALSE;
  32.  
  33.     printf("code ends ....at  %u\n", codend()  );
  34.     printf("externs start at  %u\n", externs() );
  35.     printf("externs end   at  %u\n", endext()  );
  36.     printf("free RAM ends at  %u\n", topofmem());
  37.  
  38.     exitToCpm    = FALSE;        /* not time to quit yet!    */
  39.     sizeLTentry = sizeOf(logTab[0]);    /* just had to try that feature */
  40.     outFlag    = OUTOK;        /* not p(ausing)        */
  41.  
  42.     pullMessage = FALSE;        /* not pulling a message    */
  43.     pulledMLoc    = ERROR;        /* haven't pulled one either    */
  44.     pulledMId    = ERROR;
  45.  
  46.     debug    = FALSE;
  47.     loggedIn    = FALSE;
  48.     haveCarrier = FALSE;
  49.     termWidth    = 79;
  50.     termUpper    = FALSE;
  51.     termTab    = FALSE;
  52.  
  53.     noChat    = FALSE;
  54.  
  55.     /* shave-and-a-haircut/two bits pause pattern for ringing sysop: */
  56.     shave[0]    = 40;
  57.     shave[1]    = 20;
  58.     shave[2]    = 20;
  59.     shave[3]    = 40;
  60.     shave[4]    = 80;
  61.     shave[5]    = 40;
  62.     shave[6]    =250;
  63.  
  64.     /* initialize input character-translation table:    */
  65.     for (c = 0;  c < '\40';  c++) {
  66.     filter[c] = '\0';        /* control chars -> nulls    */
  67.     }
  68.     for (c='\40'; c < 128;   c++) {
  69.     filter[c] = c;            /* pass printing chars        */
  70.     }
  71.     filter[SPECIAL]    = SPECIAL;
  72.     filter[CNTRLp]    = CNTRLp;
  73.     filter[DEL        ]    = BACKSPACE;
  74.     filter[BACKSPACE]    = BACKSPACE;
  75. /*  filter[CNTRLI   ]    = CNTRLI   ;    */
  76.     filter[XOFF     ]    = 'P'       ;
  77.     filter['\r'     ]    = NEWLINE  ;
  78.     filter[CNTRLO   ]    = 'N'       ;
  79.  
  80.     /* check for CPM 2.x */
  81.     if (!call(5, 0, 0, 12)) {
  82.     printf(" Not CPM 2.x!! Citadel's random-access won't work!\n");
  83.     exit();
  84.     }
  85.  
  86.     setSpace(homeDisk, homeUser);
  87.  
  88.     /* open message file */
  89.     msgFile    = "a:ctdlmsg.sys";
  90.     *msgFile   += msgDisk;
  91.     if ((msgfl = open(msgFile, 2)) == ERROR) {
  92.     printf(" %s not found, creating new file. \n", msgFile);
  93.     printf(" (Be sure to initialize it!)\n");
  94.     if ((msgfl = creat(msgFile)) == ERROR) {
  95.         printf("?can't create ctdlmsg.sys!!\n");
  96.         exit();
  97.     }
  98.     close(msgfl);    /* can't create in mode 2! */
  99.     msgfl = open(msgFile, 2);
  100.     }
  101.  
  102.     /* open room file */
  103.     if ((roomfl = open("ctdlroom.sys", 2)) == ERROR) {
  104.     printf(" ctdlroom.sys not found, creating new file. \n");
  105.     printf(" (Be sure to initialize it!)\n");
  106.     if ((roomfl = creat("ctdlroom.sys")) == ERROR) {
  107.         printf("?can't create ctdlroom.sys!!\n");
  108.         exit();
  109.     }
  110.     close(roomfl);     /* can't create in mode 2! */
  111.     roomfl = open("ctdlroom.sys", 2);
  112.     }
  113.  
  114.     /* open userlog file */
  115.     if ((logfl = open("ctdllog.sys", 2)) == ERROR) {
  116.     printf(" ctdlLog.sys not found, creating new file. \n");
  117.     printf(" (Be sure to initialize it!)\n");
  118.     if ((logfl = creat("ctdlLog.sys")) == ERROR) {
  119.         printf("?can't create ctdlLog.sys!!\n");
  120.         exit();
  121.     }
  122.     close(logfl);    /* can't create in mode 2! */
  123.     logfl = open("ctdlLog.sys", 2);
  124.     }
  125.  
  126.     printf("\n Erase and initialize log, message and/or room files?");
  127.     if (toUpper(getCh()) == 'Y') {
  128.     /* each of these has an additional go/no-go interrogation: */
  129.     zapMsgFile();
  130.     zapRoomFile();
  131.     zapLogFile();
  132.     }
  133.  
  134. }
  135.  
  136. /************************************************************************/
  137. /*    main() for confg.c                        */
  138. /************************************************************************/
  139. main() {
  140.     char *fBuf;
  141.     char *line;
  142.     char *cmd, *var, *string;
  143.     int  arg, arg2, args;
  144.     union {
  145.     int  *pi;
  146.     char *pc;
  147.     } nextCode;     /* where to deposit next code */
  148.  
  149.     secondsfactor = 55;
  150.     weAre = CONFIGURE;
  151.     /* icky-tricky to conserve RAM: */
  152.     echo    = BOTH;     /* echo input to console too    */
  153.     fBuf    = msgBuf;
  154.     line    = fBuf + BUFSIZ;
  155.     cmd     = line + 128;
  156.     var     = cmd  + 128;
  157.     string    = var  + 128;
  158.  
  159.  
  160.     if (fOpen("ctdlcnfg.sys", fBuf) == ERROR) {
  161.     printf("?Can't find ctdlCnfg.sys!\n");
  162.     exit();
  163.     }
  164.     nextCode.pc = &codeBuf[0];
  165.     while (fgets(line, fBuf)) {
  166.     if (args = sscanf(line, "%s %s %x ", cmd, var, &arg)) {
  167.         if          (strCmp(cmd, "#define" ) == SAMESTRING  &&  args==3) {
  168.         printf("#define '%s' as %x\n", var, arg);
  169.                if (strCmp(var, "MDATA"       )    == SAMESTRING) {
  170.             mData    = arg;
  171.         } else if (strCmp(var, "MEGAHZ"    )    == SAMESTRING) {
  172.             megaHz    = arg;
  173.         } else if (strCmp(var, "CRYPTSEED" )    == SAMESTRING) {
  174.             cryptSeed    = arg;
  175.         } else if (strCmp(var, "RCPM"       )    == SAMESTRING) {
  176.             rcpm    = arg;
  177.         } else if (strCmp(var, "CLOCK"       )    == SAMESTRING) {
  178.             clock    = arg;
  179.         } else if (strCmp(var, "MESSAGEK"  )    == SAMESTRING) {
  180.             maxMSector    = arg*8;
  181.         } else if (strCmp(var, "MSGDISK"   )    == SAMESTRING) {
  182.             msgDisk    = arg;
  183.         } else if (strCmp(var, "HOMEDISK"  )    == SAMESTRING) {
  184.             homeDisk    = arg;
  185.         } else if (strCmp(var, "HOMEUSER"  )    == SAMESTRING) {
  186.             homeUser    = arg;
  187.         } else if (strCmp(var, "LOGINOK"   )    == SAMESTRING) {
  188.             unlogLoginOk= arg;
  189.         } else if (strCmp(var, "ENTEROK"   )    == SAMESTRING) {
  190.             unlogEnterOk= arg;
  191.         } else if (strCmp(var, "READOK"    )    == SAMESTRING) {
  192.             unlogReadOk = arg;
  193.         } else if (strCmp(var, "ROOMOK"    )    == SAMESTRING) {
  194.             nonAideRoomOk=arg;
  195.         } else if (strCmp(var, "ALLMAIL"   )    == SAMESTRING) {
  196.             noMail    = !arg;
  197.         } else if (strCmp(var, "CPU8085"   )    == SAMESTRING) {
  198.             secondsfactor = (arg ? 40 : 55);
  199.         } else {
  200.             printf("? -- no variable '%s' known! -- ignored.\n", var);
  201.         }
  202.  
  203.         } else if (strCmp(cmd, "#start"  ) == SAMESTRING) {
  204.         printf("#start procedure '%s'\n", var);
  205.         if      (strCmp(var, "HANGUP"    ) == SAMESTRING) {
  206.             pHangUp    = nextCode.pc;
  207.         } else if (strCmp(var, "INITPORT"  ) == SAMESTRING) {
  208.             pInitPort    = nextCode.pc;
  209.         } else if (strCmp(var, "CARRDETECT") == SAMESTRING) {
  210.             pCarrDetect = nextCode.pc;
  211.         } else if (strCmp(var, "MIREADY"   ) == SAMESTRING) {
  212.             pMIReady    = nextCode.pc;
  213.         } else if (strCmp(var, "MOREADY"   ) == SAMESTRING) {
  214.             pMOReady    = nextCode.pc;
  215.         } else if (strCmp(var, "INITDATE"  ) == SAMESTRING) {
  216.             pInitDate    = nextCode.pc;
  217.         } else if (strCmp(var, "GETDAY"    ) == SAMESTRING) {
  218.             pGetDay    = nextCode.pc;
  219.         } else if (strCmp(var, "GETMONTH"  ) == SAMESTRING) {
  220.             pGetMonth    = nextCode.pc;
  221.         } else if (strCmp(var, "GETYEAR"   ) == SAMESTRING) {
  222.             pGetYear    = nextCode.pc;
  223.         } else printf("?--no procedure '%s' known!\n", var);
  224.  
  225.         } else if (strCmp(cmd, "#code"   ) == SAMESTRING) {
  226.         printf("#code '%s'\n", var);
  227.         if      (strCmp(var, "LOAD"       ) == SAMESTRING) {
  228.             *nextCode.pc++    = LOAD;
  229.             *nextCode.pi++    = arg;
  230.         } else if (strCmp(var, "ANDI"       ) == SAMESTRING) {
  231.             *nextCode.pc++    = ANDI;
  232.             *nextCode.pc++    = arg;
  233.        } else if (strCmp(var, "BOUT"      ) == SAMESTRING) {
  234.             *nextCode.pc++    = BOUT;
  235.         } else if (strCmp(var, "ORI"       ) == SAMESTRING) {
  236.             *nextCode.pc++    = ORI;
  237.             *nextCode.pc++    =arg;
  238.         } else if (strCmp(var, "XORI"       ) == SAMESTRING) {
  239.             *nextCode.pc++    = XORI;
  240.             *nextCode.pc++    = arg;
  241.         } else if (strCmp(var, "STORE"       ) == SAMESTRING) {
  242.             *nextCode.pc++    = STORE;
  243.             *nextCode.pi++    = arg;
  244.         } else if (strCmp(var, "LOADI"       ) == SAMESTRING) {
  245.             *nextCode.pc++    = LOADI;
  246.             *nextCode.pc++    = arg;
  247.         } else if (strCmp(var, "RET"       ) == SAMESTRING) {
  248.             *nextCode.pc++    = RET;
  249.         } else if (strCmp(var, "RET1"       ) == SAMESTRING) {
  250.             *nextCode.pc++    = RET1;
  251.         } else if (strCmp(var, "RET0"       ) == SAMESTRING) {
  252.             *nextCode.pc++    = RET0;
  253.         } else if (strCmp(var, "INP"       ) == SAMESTRING) {
  254.             *nextCode.pc++    = INP;
  255.             *nextCode.pc++    = arg;
  256.         } else if (strCmp(var, "OUTP"       ) == SAMESTRING) {
  257.             *nextCode.pc++    = OUTP;
  258.             *nextCode.pc++    = arg;
  259.         } else if (strCmp(var, "PAUSEI"    ) == SAMESTRING) {
  260.             *nextCode.pc++    = PAUSEI;
  261.             *nextCode.pc++    = arg;
  262.         } else if (strCmp(var, "ARRAY[]="  ) == SAMESTRING) {
  263.             *nextCode.pc++    = STOREX;
  264.             *nextCode.pc++    = arg;
  265.         } else if (strCmp(var, "ARRAY[]"   ) == SAMESTRING) {
  266.             *nextCode.pc++    = LOADX;
  267.             *nextCode.pc++    = arg;
  268.         } else if (strCmp(var, "OPR#"       ) == SAMESTRING) {
  269.             *nextCode.pc++    = OPRNUMBER;
  270.  
  271.             /* reparse to pick up string: */
  272.             sscanf(line, "%s %s \"%s\" %d %d",
  273.             cmd, var, string, &arg, &arg2
  274.             );
  275.             /* copy string into code buffer: */
  276.             strCpy(nextCode.pc, string);
  277.             while (*nextCode.pc++);    /* step over string    */
  278.             *nextCode.pc++    = arg;    /* lower limit        */
  279.             *nextCode.pc++    = arg2; /* upper limit        */
  280.  
  281.         } else if (strCmp(var, "OUTSTRING" ) == SAMESTRING) {
  282.             *nextCode.pc++    = OUTSTRING;
  283.  
  284.             /* reparse to pick up string: */
  285.             sscanf(line, "%s %s \"%s\"", cmd, var, string);
  286.             /* copy string into code buffer: */
  287.             strCpy(nextCode.pc, string);
  288.             while (*nextCode.pc++);    /* step over string    */
  289.             nextCode.pc--;
  290.             *nextCode.pc++    = '\r'; /* add a CR        */
  291.             *nextCode.pc++    = '\0'; /* tie off with null    */
  292.         } else printf("?--no code '%s'!\n", var);
  293.  
  294.         } else if (strCmp(cmd, "#nodeTitle") == SAMESTRING) {
  295.             /* reparse by ";" terminator: */
  296.             sscanf(line, "%s \"%s\"", cmd, string);
  297.             /* copy string into code buffer: */
  298.             strCpy(nextCode.pc, string);
  299.             nodeTitle    = nextCode.pc;
  300.             while (*nextCode.pc++);    /* step over string    */
  301.         } else if (strCmp(cmd, "#nodeName" ) == SAMESTRING) {
  302.             /* reparse by ";" terminator: */
  303.             sscanf(line, "%s \"%s\"", cmd, string);
  304.             /* copy string into code buffer: */
  305.             strCpy(nextCode.pc, string);
  306.             nodeName    = nextCode.pc;
  307.             while (*nextCode.pc++);    /* step over string    */
  308.         } else if (strCmp(cmd, "#nodeId"   ) == SAMESTRING) {
  309.             /* reparse by ";" terminator: */
  310.             sscanf(line, "%s \"%s\"", cmd, string);
  311.             /* copy string into code buffer: */
  312.             strCpy(nextCode.pc, string);
  313.             nodeId    = nextCode.pc;
  314.             while (*nextCode.pc++);    /* step over string    */
  315.         } else if (strCmp(cmd, "#alldone") == SAMESTRING) {
  316.         break;
  317.         } else if (cmd[0] == '#') printf("? -- no '%s' command!\n", cmd);
  318.     }
  319.     }
  320.     if (nextCode.pc < &codeBuf[MAXCODE]) {
  321.        init();
  322.        wrapup();
  323.     } else {
  324.     printf("\7codeBuf[] overflow! Recompile with larger MAXCODE "    );
  325.     printf("or reduce ctdlCnfg.sys\7"                );
  326.     }
  327. }
  328.  
  329. /************************************************************************/
  330. /*    wrapup() finishes up and writes ctdlTabl.sys out, finally    */
  331. /************************************************************************/
  332. wrapup() {
  333.     printf("\ncreating ctdlTabl.sys table\n");
  334.     msgInit();
  335.     indexRooms();
  336.     logInit();
  337.     printf("writeSysTab = %d\n", writeSysTab());
  338. }
  339. odeId"   ) == SAMESTRING) {
  340.             /* reparse by ";